package com.sky.web.app;

import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.AppShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
public class AppShoppingCartController {

    @Autowired
    private AppShoppingCartService shoppingCartService;

    // 添加购物车
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCart shoppingCart) {
        shoppingCartService.save(shoppingCart);
        return Result.success();
    }
    // 查询购物车
    @GetMapping("/list")
    public Result findList() {
        List<ShoppingCart> list = shoppingCartService.findList();
        return Result.success(list);
    }
    // 清空购物车
    @DeleteMapping("/clean")
    public Result clean() {
        shoppingCartService.clean();
        return Result.success();
    }

    //删减购物车
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCart shoppingCart) {
        shoppingCartService.sub(shoppingCart);
        return Result.success();
    }
}
